\doxysubsection{PID Motor Control }
\hypertarget{group___p_i_d}{}\label{group___p_i_d}\index{PID Motor Control@{PID Motor Control}}
\doxysubsubsubsection*{Classes}
\begin{DoxyCompactItemize}
\item 
struct \mbox{\hyperlink{structarm__pid__instance__q15}{arm\+\_\+pid\+\_\+instance\+\_\+q15}}
\begin{DoxyCompactList}\small\item\em Instance structure for the Q15 PID Control. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{structarm__pid__instance__q31}{arm\+\_\+pid\+\_\+instance\+\_\+q31}}
\begin{DoxyCompactList}\small\item\em Instance structure for the Q31 PID Control. \end{DoxyCompactList}\item 
struct \mbox{\hyperlink{structarm__pid__instance__f32}{arm\+\_\+pid\+\_\+instance\+\_\+f32}}
\begin{DoxyCompactList}\small\item\em Instance structure for the floating-\/point PID Control. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE float32\+\_\+t \mbox{\hyperlink{group___p_i_d_ga5a6865ed706b7dd969ef0bd58a61f306}{arm\+\_\+pid\+\_\+f32}} (\mbox{\hyperlink{structarm__pid__instance__f32}{arm\+\_\+pid\+\_\+instance\+\_\+f32}} \texorpdfstring{$\ast$}{*}S, float32\+\_\+t in)
\begin{DoxyCompactList}\small\item\em Process function for the floating-\/point PID Control. \end{DoxyCompactList}\item 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE q31\+\_\+t \mbox{\hyperlink{group___p_i_d_ga9ead8b3180125fb42879389477b99dc8}{arm\+\_\+pid\+\_\+q31}} (\mbox{\hyperlink{structarm__pid__instance__q31}{arm\+\_\+pid\+\_\+instance\+\_\+q31}} \texorpdfstring{$\ast$}{*}S, q31\+\_\+t in)
\begin{DoxyCompactList}\small\item\em Process function for the Q31 PID Control. \end{DoxyCompactList}\item 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE q15\+\_\+t \mbox{\hyperlink{group___p_i_d_ga7ecc87208cb297fb9a31cec4f18bb54e}{arm\+\_\+pid\+\_\+q15}} (\mbox{\hyperlink{structarm__pid__instance__q15}{arm\+\_\+pid\+\_\+instance\+\_\+q15}} \texorpdfstring{$\ast$}{*}S, q15\+\_\+t in)
\begin{DoxyCompactList}\small\item\em Process function for the Q15 PID Control. \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsubsection{Detailed Description}
A Proportional Integral Derivative (PID) controller is a generic feedback control loop mechanism widely used in industrial control systems. A PID controller is the most commonly used type of feedback controller.

This set of functions implements (PID) controllers for Q15, Q31, and floating-\/point data types. The functions operate on a single sample of data and each call to the function returns a single processed value. {\ttfamily S} points to an instance of the PID control data structure. {\ttfamily in} is the input sample value. The functions return the output value.

\begin{DoxyParagraph}{Algorithm\+:}

\begin{DoxyPre}
   y[n] = y[n-\/1] + A0 * x[n] + A1 * x[n-\/1] + A2 * x[n-\/2]
   A0 = Kp + Ki + Kd
   A1 = (-\/Kp ) -\/ (2 * Kd )
   A2 = Kd
\end{DoxyPre}

\end{DoxyParagraph}
\begin{DoxyParagraph}{}
where {\ttfamily Kp} is proportional constant, {\ttfamily Ki} is Integral constant and {\ttfamily Kd} is Derivative constant
\end{DoxyParagraph}
\begin{DoxyParagraph}{}

\end{DoxyParagraph}
\begin{DoxyParagraph}{}
The PID controller calculates an "{}error"{} value as the difference between the measured output and the reference input. The controller attempts to minimize the error by adjusting the process control inputs. The proportional value determines the reaction to the current error, the integral value determines the reaction based on the sum of recent errors, and the derivative value determines the reaction based on the rate at which the error has been changing.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Instance Structure}
The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure. A separate instance structure must be defined for each PID Controller. There are separate instance structure declarations for each of the 3 supported data types.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Reset Functions}
There is also an associated reset function for each data type which clears the state array.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Initialization Functions}
There is also an associated initialization function for each data type. The initialization function performs the following operations\+:
\begin{DoxyItemize}
\item Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains.
\item Zeros out the values in the state buffer.
\end{DoxyItemize}
\end{DoxyParagraph}
\begin{DoxyParagraph}{}
Instance structure cannot be placed into a const data section and it is recommended to use the initialization function.
\end{DoxyParagraph}
\begin{DoxyParagraph}{Fixed-\/\+Point Behavior}
Care must be taken when using the fixed-\/point versions of the PID Controller functions. In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. Refer to the function specific documentation below for usage guidelines.
\end{DoxyParagraph}


\label{doc-func-members}
\Hypertarget{group___p_i_d_doc-func-members}
\doxysubsubsection{Function Documentation}
\Hypertarget{group___p_i_d_ga5a6865ed706b7dd969ef0bd58a61f306}\index{PID Motor Control@{PID Motor Control}!arm\_pid\_f32@{arm\_pid\_f32}}
\index{arm\_pid\_f32@{arm\_pid\_f32}!PID Motor Control@{PID Motor Control}}
\doxysubsubsubsection{\texorpdfstring{arm\_pid\_f32()}{arm\_pid\_f32()}}
{\footnotesize\ttfamily \label{group___p_i_d_ga5a6865ed706b7dd969ef0bd58a61f306} 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE float32\+\_\+t arm\+\_\+pid\+\_\+f32 (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structarm__pid__instance__f32}{arm\+\_\+pid\+\_\+instance\+\_\+f32}} \texorpdfstring{$\ast$}{*}}]{S}{, }\item[{float32\+\_\+t}]{in}{}\end{DoxyParamCaption})}



Process function for the floating-\/point PID Control. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{in,out}}  & {\em S} & is an instance of the floating-\/point PID Control structure \\
\hline
\mbox{\texttt{in}}  & {\em in} & input sample to process \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
processed output sample. 
\end{DoxyReturn}
\Hypertarget{group___p_i_d_ga7ecc87208cb297fb9a31cec4f18bb54e}\index{PID Motor Control@{PID Motor Control}!arm\_pid\_q15@{arm\_pid\_q15}}
\index{arm\_pid\_q15@{arm\_pid\_q15}!PID Motor Control@{PID Motor Control}}
\doxysubsubsubsection{\texorpdfstring{arm\_pid\_q15()}{arm\_pid\_q15()}}
{\footnotesize\ttfamily \label{group___p_i_d_ga7ecc87208cb297fb9a31cec4f18bb54e} 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE q15\+\_\+t arm\+\_\+pid\+\_\+q15 (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structarm__pid__instance__q15}{arm\+\_\+pid\+\_\+instance\+\_\+q15}} \texorpdfstring{$\ast$}{*}}]{S}{, }\item[{q15\+\_\+t}]{in}{}\end{DoxyParamCaption})}



Process function for the Q15 PID Control. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{in,out}}  & {\em S} & points to an instance of the Q15 PID Control structure \\
\hline
\mbox{\texttt{in}}  & {\em in} & input sample to process \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
processed output sample.
\end{DoxyReturn}
\begin{DoxyParagraph}{Scaling and Overflow Behavior}
The function is implemented using a 64-\/bit internal accumulator. Both Gains and state variables are represented in 1.\+15 format and multiplications yield a 2.\+30 result. The 2.\+30 intermediate results are accumulated in a 64-\/bit accumulator in 34.\+30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.\+15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.\+15 format. 
\end{DoxyParagraph}
\Hypertarget{group___p_i_d_ga9ead8b3180125fb42879389477b99dc8}\index{PID Motor Control@{PID Motor Control}!arm\_pid\_q31@{arm\_pid\_q31}}
\index{arm\_pid\_q31@{arm\_pid\_q31}!PID Motor Control@{PID Motor Control}}
\doxysubsubsubsection{\texorpdfstring{arm\_pid\_q31()}{arm\_pid\_q31()}}
{\footnotesize\ttfamily \label{group___p_i_d_ga9ead8b3180125fb42879389477b99dc8} 
\+\_\+\+\_\+\+STATIC\+\_\+\+FORCEINLINE q31\+\_\+t arm\+\_\+pid\+\_\+q31 (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{structarm__pid__instance__q31}{arm\+\_\+pid\+\_\+instance\+\_\+q31}} \texorpdfstring{$\ast$}{*}}]{S}{, }\item[{q31\+\_\+t}]{in}{}\end{DoxyParamCaption})}



Process function for the Q31 PID Control. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{in,out}}  & {\em S} & points to an instance of the Q31 PID Control structure \\
\hline
\mbox{\texttt{in}}  & {\em in} & input sample to process \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
processed output sample.
\end{DoxyReturn}
\begin{DoxyParagraph}{Scaling and Overflow Behavior}
The function is implemented using an internal 64-\/bit accumulator. The accumulator has a 2.\+62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions. After all multiply-\/accumulates are performed, the 2.\+62 accumulator is truncated to 1.\+32 format and then saturated to 1.\+31 format. 
\end{DoxyParagraph}
